package pso;

public class Pizza extends BlackBoxFunction{
	public Pizza(int dimension){
		super(new Point(dimension, -100.0), new Point(dimension, 100.0));
	}
	
	public double evaluateHelper(Point p)
	{
		double max=Double.MIN_VALUE, min=Double.MAX_VALUE;
		double[] pVector = p.getCoordinates();
		
		for(int i=0; i<p.getDimension(); i++)
		{
			min = Math.min(min, p.getCoordinate(i));
			max = Math.max(max, p.getCoordinate(i));
		}
		
		double sum = 0;
		for(int i = 0; i < p.getDimension(); i++)
		{
			sum += pVector[i] * pVector[i];
		}
		
		if(max < 1.1 * min){
			sum *= 10 * (2 * max / min - 2.1);
		}
		return sum;
	}
}
